<template>
	<view>
		<view class="my-cart-container" v-if="cart.length!==0">
			<!-- 收货地址组件 -->
			<my-address></my-address>
			<!-- 购物车商品列表的标题区域 -->
			<view class="cart-title">
				<!-- 左侧的图标 -->
				<uni-icons type="shop" size="18"></uni-icons>
				<!-- 描述文本 -->
				<view class="cart-title-text">购物车 </view>
			</view>
			<uni-swipe-action>
				<block>
					<view v-for="(item,i) in cart" :key="i">
						<uni-swipe-action-item :right-options="options" @click='swipeActionClickHandler(item)'>
							<my-goods :goods="item" :showRadio="true" @radio-change="radioChangeHandler"
								@num-change="numberChangeHandler"></my-goods>
						</uni-swipe-action-item>
					</view>
				</block>
			</uni-swipe-action>
			<my-settle></my-settle>
		</view>
		<!-- 购物车为空时展示 -->
		<view class="empty" v-else>
			<img src="/static/empty.png">
			<text class="empty-text">空空如也~</text>
		</view>
	</view>
</template>

<script>
	import badgeMix from '../../mixins/tabbar-badge.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				options: [{
					text: '删除', //显示的文本内容
					style: {
						backgroundColor: '#dd5044'
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),
			radioChangeHandler(e) {
				this.updateGoodsState(e)
			},
			numberChangeHandler(e) {
				this.updateGoodsCount(e)
			},
			swipeActionClickHandler(item) {
				this.removeGoodsById(item.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.my-cart-container {
		padding-bottom: 50px;
	}

	.cart-title {
		height: 40px;
		align-items: center;
		display: flex;
		margin-left: 5px;
		border: 1px solid lemonchiffon;

		.cart-title-text {
			font-size: 14px;
			margin-left: 10px;
		}
	}

	.empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 120px;

		img {
			width: 200px;
			height: 200px;
		}

		.empty-text {
			font-size: 14px;
			color: gray;
			margin-top: 15px;
		}
	}
</style>